/*
 * Copyright (C) 2009 2DAI
 *
 * Este programa es Software Libre; usted puede redistribuirlo
 * y/o modificarlo bajo los términos de la "GNU General Public
 * License" como lo publica la "FSF Free Software Foundation",
 * o (a su elección) de cualquier versión posterior.
 *
 * Este programa es distribuido con la esperanza de que le será
 * útil, pero SIN NINGUNA GARANTIA; incluso sin la garantía
 * implícita por el MERCADEO o EJERCICIO DE ALGUN PROPOSITO en
 * particular. Vea la "GNU General Public License" para más
 * detalles.
 *
 * Usted debe haber recibido una copia de la "GNU General Public
 * License" junto con este programa, si no, escriba a la "FSF
 * Free Software Foundation, Inc.", 59 Temple Place - Suite 330,
 * Boston, MA  02111-1307, USA.
 */

/* 
 *
 * Created on 06-feb-2009, 8:36:13
 */
package gui;

import data.DataPlayers;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.StringTokenizer;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JTextField;
import javax.swing.text.JTextComponent;
import on.Players;
import on.Team;
import util.FormatterJFTF;

/**
 *
 * Autor : Marta Espejo
 */
public class MaintPlayers extends logic.ContentiPanel<Players> {

    private int id;
    private FormatterJFTF f;
    ArrayList<Team> equipo;
    // private Component[] c;

    /** Creates new form Players */
    public MaintPlayers() {
        initComponents();
        equipo = new DataPlayers().obtenerClub();
        rellenarLiga();
        rellenarCategoria();
        rellenarEquipo();
    }

    private String[] crearListaEquipos() {
        String[] c = new String[equipo.size()];
        int i = 0;
        for (Team clubs1 : equipo) {
            c[i] = clubs1.getNombre();            
            i++;
        }
        return c;
    }

    /*metodo que retorna el contenido de los campos en un Jugador*/
    public Players getContenido() {
        //String d=String.format("%1$tY-%1$tm-%1$t" + "e", dia);
        Players p = new Players();
        p.setId_jugadores(id);
        p.setNombre(this.JTFnombre.getText());
        p.setApellidos(this.JTFpoblacion.getText());
        p.setDni(Integer.parseInt(this.JTFdni.getText()));
        p.setNacionalidad(this.JTFnacionalidad.getText());
        if (this.JFTFfechaNacimiento.getText().compareTo(" ") != 0) {
            Date fe = convertirFecha(this.JFTFfechaNacimiento.getText());
            p.setFechaNacimiento(fe);            
        }
        p.setDireccion(this.JTFdireccion.getText());
        p.setCodigoPostal(Integer.valueOf(this.JFTFcp.getText()));
        p.setProvincia(this.JTFprovincia.getText());
        p.setPoblacion(this.JTFpoblacion.getText());
        p.setTelefono(Integer.parseInt(this.JFTFtelefono.getText()));
        p.setEMail(this.JFTFcorreo.getText());
        p.setNumLicencia(Integer.valueOf(this.JFTFnumLicencia.getText()));
        p.setCategoria(this.JCBcategoria.getItemAt(this.JCBcategoria.getSelectedIndex()).toString());
        p.setLiga(this.JCBliga.getItemAt(this.JCBliga.getSelectedIndex()).toString());
        p.setEquipo(this.JCBequipo.getItemAt(this.JCBequipo.getSelectedIndex()).toString());
        p.setNumLicencia(Integer.parseInt(this.JFTFnumLicencia.getText()));
        return p;
    }

    /*metodo que pasa un String a tipo Date*/
    private Date convertirFecha(String text) {
        int dia,mes,ano;
        //separamos la cadena en tokens
        StringTokenizer token= new StringTokenizer(text, "-");
        dia=Integer.valueOf(token.nextToken());
        mes=Integer.valueOf(token.nextToken());
        ano=Integer.valueOf(token.nextToken());
        //creacion del GregorianCalendar para pasar a Date.
        GregorianCalendar g= new GregorianCalendar(ano,mes,dia);
        return g.getTime();

    }

    /**
     * metodo que convierte la fecha en formato dd-mm-yyyy
     * @param f
     * @return
     */
    private String reConvertirFecha(Date f) {
        SimpleDateFormat año = new SimpleDateFormat("yyyy");
        SimpleDateFormat mes = new SimpleDateFormat("MM");
        SimpleDateFormat dia = new SimpleDateFormat("dd");
        String fecha = dia.format(f) + "-" + mes.format(f) + "-" + año.format(f);
        return fecha;
    }

    public void setContenido(Players p) {
        this.id = p.getId_jugadores();
        this.JTFnombre.setText(p.getNombre());
        this.JTFdni.setText(String.valueOf(p.getDni()));
        this.JTFpoblacion.setText(p.getPoblacion());
        this.JTFnombre.setText(String.valueOf(p.getNombre()));
        this.JTFnacionalidad.setText(p.getNacionalidad());
        this.JFTFfechaNacimiento.setText(reConvertirFecha(p.getFechaNacimiento()));
        this.JTFdireccion.setText(p.getDireccion());
        this.JFTFcp.setText(String.valueOf(p.getCodigoPostal()));
        this.JTFprovincia.setText(p.getProvincia());
        this.JTFapellido.setText(p.getApellidos());
        this.JFTFtelefono.setText(String.valueOf(p.getTelefono()));
        this.JFTFcorreo.setText(p.getEMail());
        this.JFTFnumLicencia.setText(String.valueOf(p.getNumLicencia()));
        this.JCBcategoria.setSelectedItem(p.getCategoria());
        this.JCBequipo.setSelectedItem(p.getEquipo());
        this.JCBliga.setSelectedItem(p.getLiga());
    }

    public void rellenarLiga() {
        Players p = new Players();
        JCBliga.setModel(new DefaultComboBoxModel(p.getArrayLiga()));
    }

    public void rellenarCategoria() {
        Players p = new Players();
        JCBcategoria.setModel(new DefaultComboBoxModel(p.getArrayCategoria()));
    }

    public void rellenarEquipo() {
        Players p = new Players();
        JCBequipo.setModel(new DefaultComboBoxModel(crearListaEquipos()));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        JTBdatos = new javax.swing.JTabbedPane();
        JPdatospersonales = new javax.swing.JPanel();
        JLnombre = new javax.swing.JLabel();
        JTFnombre = new javax.swing.JTextField();
        JLdni = new javax.swing.JLabel();
        JLfechaNacimiento = new javax.swing.JLabel();
        JLdireccion = new javax.swing.JLabel();
        JLcp = new javax.swing.JLabel();
        JLprovincia = new javax.swing.JLabel();
        JLpoblacion2 = new javax.swing.JLabel();
        JTFdni = new javax.swing.JTextField();
        JFTFfechaNacimiento = new javax.swing.JFormattedTextField();
        JTFdireccion = new javax.swing.JTextField();
        JFTFcp = new javax.swing.JFormattedTextField();
        JTFprovincia = new javax.swing.JTextField();
        JFTFtelefono = new javax.swing.JFormattedTextField();
        JLprimerApellido = new javax.swing.JLabel();
        JTFapellido = new javax.swing.JTextField();
        JLnacionalidad = new javax.swing.JLabel();
        JTFnacionalidad = new javax.swing.JTextField();
        JLpoblacion = new javax.swing.JLabel();
        JTFpoblacion = new javax.swing.JTextField();
        JLpoblacion1 = new javax.swing.JLabel();
        JFTFcorreo = new javax.swing.JFormattedTextField();
        JPdatosJugador = new javax.swing.JPanel();
        JLnumLicencia = new javax.swing.JLabel();
        JCBcategoria = new javax.swing.JComboBox();
        JCBliga = new javax.swing.JComboBox();
        JCBequipo = new javax.swing.JComboBox();
        JLequipo = new javax.swing.JLabel();
        JLliga = new javax.swing.JLabel();
        JLcategoria = new javax.swing.JLabel();
        JFTFnumLicencia = new javax.swing.JFormattedTextField();

        JLnombre.setText("Nombre");

        JLdni.setText("DNI");
        JLdni.setPreferredSize(new java.awt.Dimension(100, 14));

        JLfechaNacimiento.setText("Nacimiento");

        JLdireccion.setText("Dirección");

        JLcp.setText("CP");

        JLprovincia.setText("Provincia");

        JLpoblacion2.setText("Teléfono");

        JLprimerApellido.setText("Apellidos");

        JLnacionalidad.setText("Nacionalidad");

        JLpoblacion.setText("Población");

        JLpoblacion1.setText("Correo");

        javax.swing.GroupLayout JPdatospersonalesLayout = new javax.swing.GroupLayout(JPdatospersonales);
        JPdatospersonales.setLayout(JPdatospersonalesLayout);
        JPdatospersonalesLayout.setHorizontalGroup(
            JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(JLdireccion)
                            .addComponent(JLcp)
                            .addComponent(JLprovincia)
                            .addComponent(JLpoblacion2)
                            .addComponent(JLfechaNacimiento, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                        .addGap(61, 61, 61)
                        .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(JLdni, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(JLnombre))))
                .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                        .addGap(13, 13, 13)
                        .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                                .addGap(5, 5, 5)
                                .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(JFTFcp, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                                        .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(JFTFtelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(JTFprovincia, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                                                .addGap(23, 23, 23)
                                                .addComponent(JLpoblacion1))
                                            .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                                                .addGap(18, 18, 18)
                                                .addComponent(JLpoblacion)))
                                        .addGap(35, 35, 35)
                                        .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(JFTFcorreo)
                                            .addComponent(JTFpoblacion, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE)))
                                    .addComponent(JTFdireccion, javax.swing.GroupLayout.PREFERRED_SIZE, 342, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                                .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, JPdatospersonalesLayout.createSequentialGroup()
                                        .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(JTFnombre, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
                                            .addComponent(JTFnombre, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE))
                                        .addGap(5, 5, 5))
                                    .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                                        .addGap(5, 5, 5)
                                        .addComponent(JTFdni, javax.swing.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                                        .addComponent(JLnacionalidad)
                                        .addGap(15, 15, 15))
                                    .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                                        .addComponent(JLprimerApellido)
                                        .addGap(18, 18, 18)))
                                .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(JTFapellido)
                                    .addComponent(JTFnacionalidad, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE))
                                .addGap(7, 7, 7))))
                    .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(JFTFfechaNacimiento, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(85, 85, 85))
        );

        JPdatospersonalesLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {JFTFfechaNacimiento, JTFdni});

        JPdatospersonalesLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {JFTFtelefono, JTFprovincia});

        JPdatospersonalesLayout.setVerticalGroup(
            JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JPdatospersonalesLayout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JLnombre)
                    .addComponent(JTFnombre)
                    .addComponent(JTFapellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JLprimerApellido))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JLdni, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JLnacionalidad)
                    .addComponent(JTFnacionalidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JTFdni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JLfechaNacimiento)
                    .addComponent(JFTFfechaNacimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JLdireccion)
                    .addComponent(JTFdireccion, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JFTFcp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JLcp))
                .addGap(12, 12, 12)
                .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JTFprovincia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JLprovincia)
                    .addComponent(JLpoblacion)
                    .addComponent(JTFpoblacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(JPdatospersonalesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JFTFtelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JLpoblacion2, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JLpoblacion1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JFTFcorreo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(68, 68, 68))
        );

        JTBdatos.addTab("         Datos Personales", JPdatospersonales);

        JLnumLicencia.setText("Nº Licencia");

        JCBcategoria.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        JCBliga.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        JCBequipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        JLequipo.setText("Equipo");

        JLliga.setText("Liga");

        JLcategoria.setText("Categoria");

        javax.swing.GroupLayout JPdatosJugadorLayout = new javax.swing.GroupLayout(JPdatosJugador);
        JPdatosJugador.setLayout(JPdatosJugadorLayout);
        JPdatosJugadorLayout.setHorizontalGroup(
            JPdatosJugadorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JPdatosJugadorLayout.createSequentialGroup()
                .addGap(55, 55, 55)
                .addGroup(JPdatosJugadorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(JLequipo)
                    .addComponent(JLliga)
                    .addComponent(JLcategoria)
                    .addComponent(JLnumLicencia))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(JPdatosJugadorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JCBequipo, 0, 149, Short.MAX_VALUE)
                    .addComponent(JCBliga, 0, 149, Short.MAX_VALUE)
                    .addComponent(JCBcategoria, 0, 149, Short.MAX_VALUE)
                    .addComponent(JFTFnumLicencia, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)
                    .addComponent(JCBequipo, 0, 149, Short.MAX_VALUE)
                    .addComponent(JCBliga, 0, 149, Short.MAX_VALUE)
                    .addComponent(JCBcategoria, 0, 149, Short.MAX_VALUE)
                    .addComponent(JFTFnumLicencia, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE))
                .addGap(301, 301, 301))
        );
        JPdatosJugadorLayout.setVerticalGroup(
            JPdatosJugadorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(JPdatosJugadorLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(JPdatosJugadorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JLnumLicencia)
                    .addComponent(JFTFnumLicencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(JPdatosJugadorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JLcategoria)
                    .addComponent(JCBcategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(JPdatosJugadorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JLliga)
                    .addComponent(JCBliga, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(JPdatosJugadorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JLequipo)
                    .addComponent(JCBequipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(183, Short.MAX_VALUE))
        );

        JTBdatos.addTab("Datos Jugador", JPdatosJugador);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(JTBdatos, javax.swing.GroupLayout.DEFAULT_SIZE, 579, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(JTBdatos, javax.swing.GroupLayout.DEFAULT_SIZE, 394, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox JCBcategoria;
    private javax.swing.JComboBox JCBequipo;
    private javax.swing.JComboBox JCBliga;
    private javax.swing.JFormattedTextField JFTFcorreo;
    private javax.swing.JFormattedTextField JFTFcp;
    private javax.swing.JFormattedTextField JFTFfechaNacimiento;
    private javax.swing.JFormattedTextField JFTFnumLicencia;
    private javax.swing.JFormattedTextField JFTFtelefono;
    private javax.swing.JLabel JLcategoria;
    private javax.swing.JLabel JLcp;
    private javax.swing.JLabel JLdireccion;
    private javax.swing.JLabel JLdni;
    private javax.swing.JLabel JLequipo;
    private javax.swing.JLabel JLfechaNacimiento;
    private javax.swing.JLabel JLliga;
    private javax.swing.JLabel JLnacionalidad;
    private javax.swing.JLabel JLnombre;
    private javax.swing.JLabel JLnumLicencia;
    private javax.swing.JLabel JLpoblacion;
    private javax.swing.JLabel JLpoblacion1;
    private javax.swing.JLabel JLpoblacion2;
    private javax.swing.JLabel JLprimerApellido;
    private javax.swing.JLabel JLprovincia;
    private javax.swing.JPanel JPdatosJugador;
    private javax.swing.JPanel JPdatospersonales;
    private javax.swing.JTabbedPane JTBdatos;
    private javax.swing.JTextField JTFapellido;
    private javax.swing.JTextField JTFdireccion;
    private javax.swing.JTextField JTFdni;
    private javax.swing.JTextField JTFnacionalidad;
    private javax.swing.JTextField JTFnombre;
    private javax.swing.JTextField JTFpoblacion;
    private javax.swing.JTextField JTFprovincia;
    // End of variables declaration//GEN-END:variables

    @Override
    public void enableTextFields(boolean boo) {
        desActivar(getComponents(), boo);
//        if(boo)
//            formatear();
    }

    @Override
    public void clearTextFields() {
        enBlanco(getComponents());
//        formatear();
    }

    /**
     * metodo que recorre todos los paneles y activa op desactiva las casillas
     * @param c
     * @param boo
     */
    private void desActivar(Component[] c, boolean boo) {

        for (Component componente : c) {            
            Container con = (Container) componente;            
            if (componente.getClass().toString().compareTo("class javax.swing.JTextField") == 0 || componente.getClass().toString().compareTo("class javax.swing.JFormattedTextField") == 0 || componente.getClass().toString().compareTo("class javax.swing.JComboBox") == 0) {                
                con.setEnabled(boo);
            }
            desActivar(con.getComponents(), boo);
        }
        
    }

    /**
     * método que recorre los componentes y los pone en blanco
     * @param c
     */
    private void enBlanco(Component[] c) {

        for (Component componente : c) {            
            Container con = (Container) componente;            
            if (componente.getClass().toString().compareTo("class javax.swing.JTextField") == 0 || componente.getClass().toString().compareTo("class javax.swing.JFormattedTextField") == 0) {
                JTextComponent comp = (JTextComponent) componente;
                comp.setText("");               
            }
            enBlanco(con.getComponents());
        }
        comprobarObligatorios();        
    }

    /**
     * Matriz de textfield que contiene los campos obligatorios
     *y los pone en rojo.
     * @param c
     */
    private void comprobarObligatorios(){

        JTextField [] t= {JTFapellido,JTFpoblacion};
        for (JTextField tf : t) {
           tf.setBackground(new Color(227, 157, 171));
        }

        
    }

    public void formatear() {
        JFTFfechaNacimiento.setFormatterFactory(f.crearMascara());
    }
}
